﻿namespace FlickrDownloadr
{
    using Autofac;
    using FlickrDownloadr.Services;
    using FlickrDownloadr.Features.About;
    using FlickrNet;
    using FlickrDownloadr.Features.Shell;
    using Caliburn.Micro;
    using FlickrDownloadr.Features.DownloadOptions;

    public class FrameworkModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            //builder.RegisterType<AuthenticationProvider>().As<IAuthenticationProvider>().SingleInstance();
            //builder.RegisterType<SocialNetwork>().As<ISocialNetwork>().SingleInstance();

            builder.RegisterType<WindowManager>().As<IWindowManager>().SingleInstance();
            builder.RegisterType<EventAggregator>().As<IEventAggregator>().SingleInstance();

            //base.Load(builder);
        }
    }

    public class FeaturesModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            // Since the main library contains mostly functional features, we'll load all the types in it.
            builder.RegisterAssemblyTypes(typeof(FeaturesModule).Assembly);

            builder.RegisterType<AboutViewModel>().As<IAbout>();

            builder.RegisterType<ShellViewModel>().As<IShell>().SingleInstance();

            builder.RegisterType<DownloadOptionsViewModel>();

            //foreach (Type t in typeof(ViewModel).Assembly.GetTypes())
            //{
            //    if (typeof(ViewModel).IsAssignableFrom(t))
            //    {
            //        builder.RegisterType(t);
            //    }
            //}
        }
    }

    public class ServicesModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<FileService>().As<IFileService>();
            builder.RegisterType<PhotoService>().As<IPhotoService>();

            var flickr = FlickrFactory.GetInstance();
            builder.RegisterInstance(flickr);

            //builder.RegisterType<Flickr>().SingleInstance();

            //// Create only a single instance of the logger utility.
            //builder.RegisterType<Logger>().As<ILogger>().SingleInstance();

            //// Every single code that needs a file service should have their own instance.
            //builder.RegisterType<FileService>().As<IFileService>();
        }
    }
}
